package com.cfuture08.home.action.backMenu;

import com.cfuture08.eweb4j.component.dwz.DWZUtil;
import com.cfuture08.eweb4j.component.dwz.vo.Menu;
import com.cfuture08.eweb4j.mvc.action.Action;
import com.cfuture08.eweb4j.mvc.action.ActionSupport;
import com.cfuture08.eweb4j.orm.dao.DAO;

public class EditBackMenu extends ActionSupport {
	private Menu menu;

	public String execute() {
		if (menu.getPid() > 0) {
			if (DAO.selectOne(Menu.class, new String[] { "id" }, new String[]{String.valueOf(menu.getPid())}) == null) {
				out.print(DWZUtil.getFailedJson("修改菜单" + menu.getName()
						+ "失败,该菜单名字父节点不存在"));
				return Action.AJAX;
			}
		}
		Menu otherMenu = DAO.selectOne(menu, new String[] { "name" });
		if (otherMenu != null && otherMenu.getId() != menu.getId()) {
			out.print(DWZUtil.getFailedJson("修改菜单" + menu.getName()
					+ "失败,该菜单名已经存在"));
		} else {
			out.print(DAO.update(menu) == true ? DWZUtil.getSuccessJson("修改菜单"
					+ menu.getName() + "成功", "xssycd", "showAllBackMenu.do", null)
					: DWZUtil.getFailedJson("修改菜单" + menu.getName() + "失败"));
		}
		return Action.AJAX;
	}

	public Menu getMenu() {
		return menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}
}
